﻿using UnityEngine;
using System.Collections;

public class Tile : MonoBehaviour 
{
	private bool m_hasDestroyed;
	// Use this for initialization
	void Start () 
	{
		m_hasDestroyed = false;
	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}
	void OnCollisionEnter2D(Collision2D coll) 
	{
		if (m_hasDestroyed) 
		{
			Debug.Log ("Already Destroyed");
			return;
		}
		if( coll.gameObject.tag == "Missile" && gameObject.tag != "NonBreakableWall")
		{
			Debug.Log(coll.gameObject.tag + " hit " + gameObject.tag );
			//Hit by a Missile, so destroy it
			Debug.Log("Destroying " + gameObject.name);
			m_hasDestroyed = true;
			Destroy(gameObject);
			gameObject.SetActive( false );
		}
	}
}
